package com.hengxinguotong.zhihuichengjian.adapter;

import android.content.Context;
import android.view.View;
import android.view.ViewGroup;
import android.widget.RelativeLayout;

import com.hengxinguotong.zhihuichengjian.R;
import com.hengxinguotong.zhihuichengjian.bean.Menu;
import com.hengxinguotong.zhihuichengjian.treeview.RecyclerAdapter;
import com.hengxinguotong.zhihuichengjian.widget.font.HXTextView;

import java.util.List;

import butterknife.BindView;
import butterknife.ButterKnife;

/**
 * @CopyRight 恒信国通信息科技
 * @Author WuLei
 * @Date 2019/1/11
 */

public class BuildMenuAdapter extends RecyclerAdapter<Menu, BuildMenuAdapter.BuildMenuViewHolder> {

    public BuildMenuAdapter(Context context, List<Menu> dataList) {
        super(context, dataList);
    }

    @Override
    public BuildMenuViewHolder onCreateViewHolder(ViewGroup parent, int viewType) {
        View view = View.inflate(context, R.layout.item_build_menu, null);
        return new BuildMenuViewHolder(view);
    }

    @Override
    public void onBindViewHolder(BuildMenuViewHolder holder, int position) {
        holder.bindData(position);
    }

    public class BuildMenuViewHolder extends RecyclerAdapter.BaseViewHolder<Menu>
    {
        @BindView(R.id.item_rl)
        RelativeLayout itemRl;
        @BindView(R.id.menu_name)
        HXTextView menuName;
        @BindView(R.id.english_name)
        HXTextView englishName;

        public BuildMenuViewHolder(View itemView) {
            super(itemView);
            ButterKnife.bind(this, itemView);
        }

        @Override
        public void bindData(final int position) {
            final Menu menu = dataList.get(position);
            itemRl.setBackgroundResource(menu.getIcon());
            menuName.setText(menu.getTitle());
            englishName.setText(menu.getEnglishName());
            itemView.setOnClickListener(new View.OnClickListener() {
                @Override
                public void onClick(View v) {
                    onItemClickListener.onItemClick(itemView, menu, position);
                }
            });
        }
    }
}
